home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / amigadoslibrary / flush.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  1KB  |  70 lines

  1. /* Flush.c   V1.2   93-03-03                   */
  2. /* ROM library: "dos.library/Flush", (V36+)    */
  3. /* Copyright 1993, Anders Bjerin, Amiga C Club */
  4.  
  5. #include <dos/dos.h>
  6.  
  7. #include <clib/dos_protos.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #define BUFFER_SIZE 14
  12.  
  13. UBYTE *version = "$VER: Flush 1.2";
  14.  
  15. int main( int argc, char *argv[] );
  16. int main( int argc, char *argv[] )
  17. {
  18.   int loop;
  19.   BPTR my_file;
  20.   int actual;
  21.   BOOL ok;
  22.   UBYTE my_read_buffer[ BUFFER_SIZE ];
  23.   UBYTE my_write_buffer[ BUFFER_SIZE ] =
  24.   {
  25.     '!', 'b', 'u', 'l', 'C', ' ', 'C', ' ', 'a', 'g', 'i', 'm', 'A', '\n'
  26.   };
  27.  
  28.  
  29.   /* Open a new file: */
  30.   my_file = Open( "RAM:ReadThis.dat", MODE_NEWFILE );
  31.   if( !my_file )
  32.     exit( 20 );
  33.  
  34.   /* Use a buffered output routine: */
  35.   for( loop = BUFFER_SIZE - 1; loop >= 0; loop-- )
  36.   {
  37.     actual = FPutC( my_file, my_write_buffer[ loop ] );
  38.     if( actual == -1 )
  39.     {
  40.       Close( my_file );
  41.       exit( 21 );
  42.     }
  43.   }
  44.  
  45.   /* Flush the temporary dos buffer: */
  46.   ok = Flush( my_file );
  47.  
  48.   /* Any problems? */
  49.   if( ok )
  50.     printf( "Buffer was flushed successfully!\n" );
  51.   else
  52.     printf( "Problems while flushing the buffer!\n" );
  53.  
  54.   /* Move to the begining of the file */
  55.   Seek( my_file, 0, OFFSET_BEGINNING );
  56.  
  57.   /* Use a un-buffered input routine: */
  58.   actual = Read( my_file, my_read_buffer, BUFFER_SIZE );
  59.   if( actual != BUFFER_SIZE )
  60.   {
  61.     Close( my_file );
  62.     exit( 23 );
  63.   } 
  64.   
  65.   printf( "%s\n", my_read_buffer );
  66.  
  67.   Close( my_file );
  68.   exit( 0 );
  69. }
  70.